home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / asm / amislib.exe / NOTE.ASM < prev    next >
Assembly Source File  |  1992-09-12  |  26KB  |  1,010 lines

  1. ;-----------------------------------------------------------------------
  2. ; NOTE.ASM    Public Domain 1992 Ralf Brown
  3. ;        You may do with this software whatever you want, but
  4. ;        common courtesy dictates that you not remove my name
  5. ;        from it.
  6. ;
  7. ; Popup to append one or more lines to a text file.  Demonstration of the
  8. ; use of DOS from within an AMIS-compliant TSR.
  9. ; Note: popup may be done from the commandline or via a hotkey; however,
  10. ;     the hotkey support requires a newer BIOS which has the INT 15/4F
  11. ;    keyboard intercept
  12. ;
  13. ; Version 0.90
  14. ; LastEdit: 9/10/92
  15. ;-----------------------------------------------------------------------
  16.  
  17. __TINY__ equ 1                ; using Tiny model
  18.     INCLUDE AMIS.MAC
  19.  
  20.     @Startup 3,00            ; need DOS 3.00
  21.                     ; this macro also takes care of declaring
  22.                     ; all the segments in the required order
  23.  
  24. ;-----------------------------------------------------------------------
  25. ;
  26. VERSION_NUM equ 005Ah    ; v0.90
  27. VERSION_STR equ "0.90"
  28.  
  29. ; uncomment the following line to use the generic hotkey dispatcher, at a cost
  30. ; of an additional 80 bytes
  31. ;CUSTOM_HOTKEY_CODE equ 1
  32.  
  33. WINDOW_TOP    equ 0        ; topmost row of TSR's popup window
  34. WINDOW_LEFT   equ 5        ; leftmost column of TSR's popup window
  35. WINDOW_HEIGHT equ 3           ; height (including frame) of popup window
  36. WINDOW_WIDTH  equ 70          ; width (including frame) of popup window
  37. LOCAL_STACK_SIZE equ 128    ; size of local stack in bytes
  38. HOTKEY_SCAN   equ SCAN_N    ; scan code for 'N' key
  39. HOTKEY_NAME   equ "N"
  40.  
  41. LODSB_ES MACRO
  42.     DB 26h,0ACh    ; LODSB ES:
  43.     ENDM
  44.  
  45. ;-----------------------------------------------------------------------
  46. ; Put the resident code into its own segment so that all the offsets are
  47. ; proper for the new location after copying it into a UMB or down into
  48. ; the PSP.
  49. ;
  50. TSRcode@
  51.  
  52. ;-----------------------------------------------------------------------
  53. ; Since we need a PSP, but might be loaded into a UMB or at the top of
  54. ; conventional memory, we make a copy of the all-important first 64 bytes
  55. ; of the PSP here.  After relocation, this copy will start at offset 0
  56. ;
  57. TSR_PSP    db 64 dup (?)
  58.  
  59. ;-----------------------------------------------------------------------
  60. ; TSR's initialized data storage
  61. ;
  62. TSRdata@
  63. TSR_name    db "NOTE",0        ; title for popup window
  64.  
  65. int13_25_busy label word    ; allow both to be tested in one operation
  66. int13_busy    db 0
  67. int25_busy    db 0
  68. int26_TSR_busy label word    ; allow both to be tested in one operation
  69. int26_busy    db 0
  70. TSR_activated    db 0
  71. want_popup    db 0
  72. want_shutdown    db 0
  73. popup_INT28    db 0
  74.  
  75. ;;; add TSR-specific initialized data below
  76.  
  77. CRLF_buffer    db 13,10
  78.  
  79. TSRdataEnd@
  80.  
  81. ;-----------------------------------------------------------------------
  82. ; TSR's uninitialized data storage
  83. ;
  84. TSRbss@
  85. INDOS_ptr    dd ?
  86. CRITERR_ptr    dd ?
  87. interrupted_DTA    dd ?
  88. interrupted_PSP dw ?
  89. interrupted_SP    dw ?
  90. interrupted_SS    dw ?
  91.  
  92. interrupted_cursorpos dw ?
  93. display_page_attr label word
  94. display_attr    db ?
  95. display_page    db ?
  96. screen_width    db ?
  97.  
  98. cursor_pos label word
  99. cursor_x    db ?
  100. cursor_y    db ?
  101.  
  102. screen_buffer     db (WINDOW_HEIGHT*WINDOW_WIDTH*2) dup (?)
  103. local_stack     db LOCAL_STACK_SIZE dup (?)
  104. local_stack_bottom label byte
  105.  
  106. ;;; add TSR-specific uninitialized data below
  107.  
  108. notefile_handle dw ?
  109.  
  110. edit_buffer    db WINDOW_WIDTH-2 dup (?)
  111. TSRbssEnd@
  112.  
  113.  
  114. ;-----------------------------------------------------------------------
  115.  
  116. TSR_main proc near
  117.     ASSUME    DS:TGROUP,ES:NOTHING
  118.     xor    si,si            ; SI stores line length
  119. TSR_main_loop:
  120.     mov    dx,256*(WINDOW_TOP+1) + (WINDOW_LEFT+1)
  121.     add    dx,si
  122.     call    TSR_move_cursor
  123.     call    TSR_getkey
  124.     cmp    al,0Dh            ; Enter pressed?
  125.     je    TSR_main_line_end
  126.     cmp    al,27            ; Esc pressed?
  127.     je    TSR_main_done
  128.     cmp    al,8
  129.     je    backspace
  130.     cmp    al,0            ; extended ASCII?
  131.     je    TSR_main_loop        ; if yes, ignore
  132.     cmp    al,0E0h
  133.     jne    got_char
  134.     cmp    ah,0
  135.     jne    TSR_main_loop
  136. got_char:
  137.     cmp    si,WINDOW_WIDTH-2
  138.     jb    store_char
  139. beep:
  140.     mov    ax,0E07h        ; beep
  141.     int    10h
  142.     jmp    TSR_main_loop
  143. store_char:
  144.     mov    edit_buffer[si],al
  145.     inc    si            ; remember that we got another char
  146.     call    TSR_put_char
  147.     jmp    TSR_main_loop
  148.  
  149. backspace:
  150.     or    si,si
  151.     jz    beep
  152.     dec    si
  153.     mov    dx,256*(WINDOW_TOP+1) + (WINDOW_LEFT+1)
  154.     add    dx,si
  155.     call    TSR_move_cursor
  156.     mov    al,' '
  157.     call    TSR_put_char
  158.     jmp    TSR_main_loop
  159.  
  160. TSR_main_line_end:
  161.     mov    ah,40h
  162.     mov    bx,notefile_handle
  163.     mov    cx,si
  164.     mov    dx,offset TGROUP:edit_buffer
  165.     int    21h
  166.     mov    ah,40h
  167.     mov    cx,2
  168.     mov    dx,offset TGROUP:CRLF_buffer
  169.     int    21h
  170.     call    TSR_clear_window
  171.     jmp    TSR_main        ; restart for next line
  172.  
  173. TSR_main_done:
  174.     mov    bx,notefile_handle
  175.     mov    ah,45h            ; DUP handle
  176.     int    21h
  177.     jc    TSR_main_exit        ; quit now if unable to duplicate
  178.     mov    bx,ax
  179.     mov    ah,3Eh            ; close duplicate
  180.     int    21h
  181. TSR_main_exit:
  182.     ret
  183. TSR_main endp
  184.  
  185. ;-----------------------------------------------------------------------
  186. ; Function that performs any necessary cleanup prior to the TSR being
  187. ; removed from memory.  At the time it is called, the TSR is effectively
  188. ; popped up, though it has not modified the screen.  If this routine needs
  189. ; to write on the screen, it must save and restore the screen contents
  190. ; itself
  191. ;
  192. TSR_shutdown proc near
  193.     mov    bx,notefile_handle
  194.     mov    ah,3Eh            ; close the file
  195.     int    21h
  196.     ret
  197. TSR_shutdown endp
  198.  
  199. ;-----------------------------------------------------------------------
  200.  
  201. TSR_INT24_handler:
  202.     mov    al,03h            ; FAIL, for now
  203. ;    iret  ; save a byte by falling through to next handler
  204.  
  205. ;-----------------------------------------------------------------------
  206. ; Simply ignore Ctrl-Break and Ctrl-C interrupts
  207. ;
  208. TSR_INT1B_handler:
  209. TSR_INT23_handler:
  210.     iret
  211.  
  212. ;=======================================================================
  213. ; It should not be necessary to make any changes between here and the
  214. ; end of the resident portion (other than the TSR identifier in the ALTMPX
  215. ; macro) in order to modify this code for a different purpose.
  216. ;=======================================================================
  217.  
  218. ;-----------------------------------------------------------------------
  219. ;
  220. TSR_getkey proc near
  221.     mov    ah,11h            ; keystroke available?
  222.     int    16h
  223.     jnz    TSR_getkey_got_one    ; if yes, get it, otherwise
  224.     int    28h            ; give other TSRs a chance to do work
  225.     jmp    TSR_getkey
  226. TSR_getkey_got_one:
  227.     mov    ah,10h            ; get the keystroke
  228.     int    16h
  229.     ret
  230. TSR_getkey endp
  231.  
  232. ;-----------------------------------------------------------------------
  233. ; entry: DH = row, DL = column
  234. ;
  235. TSR_move_cursor proc near
  236.     ASSUME    DS:TGROUP,ES:NOTHING
  237.     mov    cursor_pos,dx
  238.     mov    bh,display_page
  239.     mov    ah,2            ; BIOS move-cursor function
  240.     int    10h
  241.     ret
  242. TSR_move_cursor endp
  243.  
  244. ;-----------------------------------------------------------------------
  245. ; exit: AX,BX,CX,DX destroyed
  246. ;
  247. TSR_put_char_186 proc near
  248.     mov    al,186
  249.     ;; fall through to TSR_put_char
  250. TSR_put_char_186 endp
  251.  
  252. ;-----------------------------------------------------------------------
  253. ; entry: AL = char
  254. ; exit: AH,BX,CX,DX destroyed
  255. ;
  256. TSR_put_char proc near
  257.     mov    cx,1
  258.     ;; fall through to TSR_put_line
  259. TSR_put_char endp
  260.  
  261. ;-----------------------------------------------------------------------
  262. ; entry: AL = char, CX = repeat count
  263. ; exit: AX,BX,CX,DX destroyed
  264. ;
  265. TSR_put_line proc near
  266.     ASSUME    DS:TGROUP,ES:NOTHING
  267.     add    cursor_x,cl
  268.     mov    bx,display_page_attr
  269.     mov    ah,9
  270.     int    10h
  271.     mov    al,cursor_x
  272.     cmp    al,screen_width
  273.     jb    TSR_put_line_done
  274.     mov    cursor_x,0
  275.     inc    cursor_y
  276. ;
  277. ; need to handle case of falling off the bottom
  278. ;
  279.  
  280.  
  281. TSR_put_line_done:
  282.     mov    dx,cursor_pos
  283.     mov    ah,2            ; set cursor position
  284.     int    10h
  285.     ret
  286. TSR_put_line endp
  287.  
  288. ;-----------------------------------------------------------------------
  289.  
  290. save_screen proc near
  291.     ASSUME    DS:TGROUP,ES:NOTHING
  292.     mov    ah,0Fh
  293.     int    10h            ; get video mode and active page
  294.     mov    display_page,bh
  295.     mov    screen_width,ah
  296.     mov    ah,3            ; get cursor position on page BH
  297.     int    10h
  298.     mov    interrupted_cursorpos,dx
  299.     push    ds
  300.     pop    es
  301.     ASSUME    ES:TGROUP
  302.     mov    di,offset TGROUP:screen_buffer
  303.     mov    dh,WINDOW_TOP
  304. save_screen_loop1:
  305.     mov    dl,WINDOW_LEFT
  306. save_screen_loop2:
  307.     mov    ah,2            ; set cursor position on page BH
  308.     int    10h
  309.     mov    ah,8            ; read character&attribute on page BH
  310.     int    10h
  311.     stosw                ; and remember